package dev.erge.net;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author erge
 */
public class UDPServerSample {

    public static void main(String[] args) {
        try {
            byte[] bytes = new byte[1024];
            DatagramPacket packet = new DatagramPacket(bytes, bytes.length);
            DatagramSocket socket = new DatagramSocket(8088);
            socket.receive(packet);
            String recvMsg = new String(packet.getData(), 0, packet.getLength());
            System.out.println(packet.getLength());
            System.out.println(recvMsg);
            socket.close();
        } catch (SocketException ex) {
            Logger.getLogger(UDPServerSample.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(UDPServerSample.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
